package com.geek.mysql7work.work3;

import com.geek.mysql7work.work1.DBManagerV1;
import com.geek.mysql7work.work1.InsertTest;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.sql.SQLException;

@Component
public class TestMasterSlave implements InitializingBean {


    @Autowired
    private GeekOrderRepository geekOrderRepository;

    //    @PostConstruct
    public void testAddMaster() {
        Connection conn = null;
        DBManagerV1 dbManagerV1 = new DBManagerV1();
        conn = dbManagerV1.getConnection(); //获取连接
        if (conn != null) {
            System.out.println("work3获取连接成功");
            InsertTest insertTest = new InsertTest();
            insertTest.insert(conn);
        } else {
            System.out.println("获取连接失败");
        }
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        testFind();
    }

    private void testFind() throws SQLException {
        GeekOrder geekOrder = geekOrderRepository.findById(1L).get();
        System.out.println("work3data" + geekOrder);


    }
}
